package com.deyinet.bdcms.core.common;

/**
 * Created by Administrator on 2017/3/27 0027.
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.deyinet.bdcms.core.exception.CheckException;
import java.util.List;

public class JsonParseTool {
    public JsonParseTool() {
    }

    public static <T> List<T> parseArray(String json, Class<T> tClass, String errorMsg) {
        try {
            return JSON.parseArray(json, tClass);
        } catch (Exception var4) {
            throw new CheckException(errorMsg);
        }
    }

    public static <T> JSONArray parseArray(String json, String errorMsg) {
        try {
            return JSON.parseArray(json);
        } catch (Exception var3) {
            var3.printStackTrace();
            throw new CheckException(errorMsg);
        }
    }

    public static <T> JSONObject parseObject(String json, String error) {
        try {
            return JSON.parseObject(json);
        } catch (Exception var3) {
            var3.printStackTrace();
            throw new CheckException(error);
        }
    }

    public static <T> T parseObject(String json, Class<T> tClass, String error) {
        try {
            return JSON.parseObject(json, tClass);
        } catch (Exception var4) {
            var4.printStackTrace();
            throw new CheckException(error);
        }
    }

    public static String toJson(Object obj) {
        return JSON.toJSONString(obj);
    }
}

